<template>
  <div class="preview-container">
    <el-dialog
      :title="Title"
      width="900px"
      :visible="isShow"
      @close="handleClose"
      v-loading="loading"
    >
      <!-- 基本 -->
      <el-row>
        <el-col :span="6">【题型】：{{ MyData.questionType | tx }}</el-col>
        <el-col :span="6">【编号】：{{ MyData.id }}</el-col>
        <el-col :span="6">【难度】：{{ MyData.difficulty | nd }}</el-col>
        <el-col :span="6">【标签】：{{ MyData.tags }}</el-col>
        <el-col :span="6">【学科】：{{ MyData.subjectName }}</el-col>
        <el-col :span="6">【目录】：{{ MyData.directoryName }}</el-col>
        <el-col :span="6">【方向】：{{ MyData.direction }}</el-col>
      </el-row>
      <hr />
      <!-- 题干 -->
      【题干】：
      <div v-if="MyData.questionType !== '3'">
        <div v-html="MyData.question" style="color: blue"></div>
        <div style="padding-bottom: 5px">
          {{ MyData.questionType | tx }}选项：（以下选中的选项为正确答案）
        </div>
        <div
          v-for="item in MyData.options"
          :key="item.id"
          style="padding: 5px 0"
        >
          <el-radio
            v-if="MyData.questionType === '1'"
            :value="item.isRight"
            :label="1"
            >{{ item.title }}</el-radio
          >
          <el-checkbox
            v-if="MyData.questionType === '2'"
            :value="item.isRight ? true : false"
            :label="item.title"
          ></el-checkbox>
        </div>
      </div>
      <hr />
      <!-- 参考答案 -->
      【参考答案】：
      <div style="display: inline-block">
        <el-button type="danger" size="small" @click="previewVideo"
          >视频答案预览</el-button
        >
      </div>
      <div  v-show="videoPlay" class="video">
        <video ref="video" :src="MyData.videoURL" controls></video>
      </div>
      <hr />
      <!-- 答案解析 -->
      【答案解析】：
      <div v-html="MyData.answer" style="display: inline-block"></div>
      <hr>
      <!-- 题目备注 -->
      【题目备注】：
      <div style="display: inline-block">
        {{MyData.remarks}}
      </div>
      <template #footer>
        <el-button type="primary" @click="handleClose">关闭</el-button>
      </template>
    </el-dialog>
  </div>
</template>

<script>
import { detail as questionDetail } from '@/api/hmmm/questions.js'
import { questionType, difficulty } from '@/api/hmmm/constants.js'
export default {
  props: {
    data: {
      type: Object,
      default: () => {}
    }
  },
  data () {
    return {
      Title: '题目预览',
      isShow: false,
      loading: false,
      videoPlay: false,
      MyData: {}
    }
  },
  methods: {
    handleClose () {
      this.isShow = false
      this.MyData = {}
      this.$refs.video.pause()
    },
    async open () {
      this.isShow = true
      this.loading = true
      const { data } = await questionDetail(this.data)
      console.log(data)
      this.MyData = data
      this.loading = false
    },
    // 视频
    previewVideo () {
      this.videoPlay = true
      this.$refs.video.play()
    }
  },
  filters: {
    tx (value) {
      if (value) {
        return questionType.find((item) => item.value === +value).label + '题'
      }
    },
    nd (value) {
      if (value) return difficulty.find((item) => item.value === +value).label
    }
  }
}
</script>

<style scoped lang='scss'>
.preview-container {
  .el-col {
    padding: 10px 0;
  }
  .video {
    width: 400px;
    height: 300px;
    video {
      width: 100%;
      height: 100%;
    }
  }
}
</style>
